﻿/********************************************************************
	created:	2011-8-12   7:19
	author:		Lifan Su
	
	purpose:	interface of the functions that 
                convert int to byte array or convert byte array to integer
*********************************************************************/

#ifndef CVT_INT_MEM_H
#define CVT_INT_MEM_H

#if defined _MSC_VER
    #if defined CVT_INT_MEM_DYNAMIC_EXPORTS
        #define CVT_INT_MEM_PREFIX __declspec(dllexport)
    #elif defined CVT_INT_MEM_DYNAMIC
        #define CVT_INT_MEM_PREFIX __declspec(dllimport)
    #else
        #define CVT_INT_MEM_PREFIX
    #endif
    
    #define CVT_INT_MEM_API 
#else
    #error "Unsupported platform"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include <_stdint.h>
    //  convert from big-endian byte array to unsigned integer
    CVT_INT_MEM_PREFIX uint8_t  CVT_INT_MEM_API cvt_byte_to_u08_be(const void *);
    CVT_INT_MEM_PREFIX uint16_t CVT_INT_MEM_API cvt_byte_to_u16_be(const void *);
    CVT_INT_MEM_PREFIX uint32_t CVT_INT_MEM_API cvt_byte_to_u32_be(const void *);
    CVT_INT_MEM_PREFIX uint64_t CVT_INT_MEM_API cvt_byte_to_u64_be(const void *);

    //  convert from little-endian byte array to unsigned integer
    CVT_INT_MEM_PREFIX uint8_t  CVT_INT_MEM_API cvt_byte_to_u08_le(const void *);
    CVT_INT_MEM_PREFIX uint16_t CVT_INT_MEM_API cvt_byte_to_u16_le(const void *);
    CVT_INT_MEM_PREFIX uint32_t CVT_INT_MEM_API cvt_byte_to_u32_le(const void *);
    CVT_INT_MEM_PREFIX uint64_t CVT_INT_MEM_API cvt_byte_to_u64_le(const void *);


    //  convert from unsigned integer to big-endian byte array
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u08_be_to_byte(void *, uint8_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u16_be_to_byte(void *, uint16_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u32_be_to_byte(void *, uint32_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u64_be_to_byte(void *, uint64_t);

    //  convert from unsigned integer to little-endian byte array
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u08_le_to_byte(void *, uint8_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u16_le_to_byte(void *, uint16_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u32_le_to_byte(void *, uint32_t);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_u64_le_to_byte(void *, uint64_t);


    //  convert between big and little endian unsigned integer
    CVT_INT_MEM_PREFIX uint8_t  CVT_INT_MEM_API cvt_u08_endian(uint8_t);
    CVT_INT_MEM_PREFIX uint16_t CVT_INT_MEM_API cvt_u16_endian(uint16_t);
    CVT_INT_MEM_PREFIX uint32_t CVT_INT_MEM_API cvt_u32_endian(uint32_t);
    CVT_INT_MEM_PREFIX uint64_t CVT_INT_MEM_API cvt_u64_endian(uint64_t);

    //  convert between big and little endian unsigned byte array
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_b08_endian(void *, const void *);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_b16_endian(void *, const void *);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_b32_endian(void *, const void *);
    CVT_INT_MEM_PREFIX void     CVT_INT_MEM_API cvt_b64_endian(void *, const void *);

#ifdef __cplusplus
}
#endif

#endif // CVT_INT_MEM_H